<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title><?php echo ($meta_title); ?>|惠Go管理平台</title>
    
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/base.css" media="all">
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/common.css" media="all">
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/module.css">
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/style.css" media="all">
	<link rel="stylesheet" type="text/css" href="/Public/Admin/css/<?php echo (C("COLOR_STYLE")); ?>.css" media="all">
     <!--[if lt IE 9]>
    <script type="text/javascript" src="/Public/static/jquery-1.10.2.min.js"></script>
    <![endif]--><!--[if gte IE 9]><!-->
    <script type="text/javascript" src="/Public/static/jquery-2.0.3.min.js"></script>
    <script type="text/javascript" src="/Public/Admin/js/jquery.mousewheel.js"></script>
    <!--<![endif]-->
    
</head>
<body>
    <!-- 头部 -->
    <div class="header">
        <!-- Logo -->
        <span class="logo" style="color: snow;font-size: 23px;font-weight: bold">惠       Go</span>
        <!-- /Logo -->

        <!-- 主导航 -->
        <ul class="main-nav">
            <?php if(is_array($__MENU__["main"])): $i = 0; $__LIST__ = $__MENU__["main"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$menu): $mod = ($i % 2 );++$i;?><li class="<?php echo ((isset($menu["class"]) && ($menu["class"] !== ""))?($menu["class"]):''); ?>"><a href="<?php echo (u($menu["url"])); ?>"><?php echo ($menu["title"]); ?></a></li><?php endforeach; endif; else: echo "" ;endif; ?>
        </ul>
        <!-- /主导航 -->

        <!-- 用户栏 -->
       <div class="user-bar">
            <a href="javascript:;" class="user-entrance"><i class="icon-user"></i></a>
            <ul class="nav-list user-menu hidden">
                <li class="manager">你好，<em title="<?php echo session('user_auth.username');?>"><?php echo session('user_auth.username');?></em></li>
                <li><a href="<?php echo U('User/updatePassword');?>">修改密码</a></li>
                <li><a href="<?php echo U('User/updateNickname');?>">修改昵称</a></li>
                <li><a href="<?php echo U('Public/logout');?>">退出</a></li>
            </ul>
        </div>
    </div>
    <!-- /头部 -->

    <!-- 边栏 -->
    <div class="sidebar">
        <!-- 子导航 -->
        
            <div id="subnav" class="subnav">
                <?php if(!empty($_extra_menu)): ?>
                    <?php echo extra_menu($_extra_menu,$__MENU__); endif; ?>
                <?php if(is_array($__MENU__["child"])): $i = 0; $__LIST__ = $__MENU__["child"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$sub_menu): $mod = ($i % 2 );++$i;?><!-- 子导航 -->
                    <?php if(!empty($sub_menu)): if(!empty($key)): ?><h3><i class="icon icon-unfold"></i><?php echo ($key); ?></h3><?php endif; ?>
                        <ul class="side-sub-menu">
                            <?php if(is_array($sub_menu)): $i = 0; $__LIST__ = $sub_menu;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$menu): $mod = ($i % 2 );++$i;?><li>
                                    <a class="item" href="<?php echo (u($menu["url"])); ?>"><?php echo ($menu["title"]); ?></a>
                                </li><?php endforeach; endif; else: echo "" ;endif; ?>
                        </ul><?php endif; ?>
                    <!-- /子导航 --><?php endforeach; endif; else: echo "" ;endif; ?>
            </div>
        
        <!-- /子导航 -->
    </div>
    <!-- /边栏 -->

    <!-- 内容区 -->
    <div id="main-content">
        <div id="top-alert" class="fixed alert alert-error" style="display: none;">
            <button class="close fixed" style="margin-top: 4px;">&times;</button>
            <div class="alert-content">这是内容</div>
        </div>
        <div id="main" class="main">
            
            <!-- nav -->
            <?php if(!empty($_show_nav)): ?><div class="breadcrumb">
                <span>您的位置:</span>
                <?php $i = '1'; ?>
                <?php if(is_array($_nav)): foreach($_nav as $k=>$v): if($i == count($_nav)): ?><span><?php echo ($v); ?></span>
                    <?php else: ?>
                    <span><a href="<?php echo ($k); ?>"><?php echo ($v); ?></a>&gt;</span><?php endif; ?>
                    <?php $i = $i+1; endforeach; endif; ?>
            </div><?php endif; ?>
            <!-- nav -->
            

            
	<script type="text/javascript" src="/Public/static/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2><?php echo isset($info['id'])?'编辑':'新增';?>商品</h2>
    </div>
    <div class="tab-wrap">
    	<ul class="tab-nav nav">
			<li data-tab="tab1" class="current"><a href="javascript:void(0);">基 础</a></li>
			<li data-tab="tab2"><a href="javascript:void(0);">资 料</a></li>
		<!--	<li data-tab="tab3"><a href="javascript:void(0);">分 类</a></li>
			<li data-tab="tab4"><a href="javascript:void(0);">扩 展</a></li>-->
			<li data-tab="tab5"><a href="javascript:void(0);">选 项</a></li>
		</ul>
		<div class="tab-content">
    		<form action="/Admin/Product/add/type/putong.html" method="post" class="form-horizontal" autocomplete="off">
		    	<div id="tab1" class="tab-pane in tab1">
				     <div class="form-item">
				     	<label class="item-label">商品名称</label>
				     	<div class="controls">
				     		<input type="text" class="text input-large" name="title" value="<?php echo ($info["title"]); ?>" placeholder="商品名称">
				     	</div>
				     </div>
				     <div class="form-item">
				     	<label class="item-label">商品描述</label>
				     	<div class="controls">
				     		<label class="textarea">
				     			<textarea name="description" placeholder="商品描述"><?php echo ($info["description"]); ?></textarea>
				     			<?php echo hook('adminArticleEdit', array('name'=>'description','value'=>$info['description']));?>
				     		</label>
				     	</div>
				     </div>

				 </div>
				 <div id="tab2" class="tab-pane tab2">

				 	<div class="form-item">
				     	<label class="item-label">商品图片</label>
				     	<div class="controls">
				     		<input type="file" id="upload_picture">
				     		<div class="upload-img-box">
				     			<?php if(is_array($pics)): $i = 0; $__LIST__ = $pics;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$pic): $mod = ($i % 2 );++$i;?><div class="upload-pre-item"><input type="hidden" name="pic[]" value="<?php echo ((isset($pic["cover_id"]) && ($pic["cover_id"] !== ""))?($pic["cover_id"]):''); ?>"/><img src="<?php echo (get_cover($pic["cover_id"],'path')); ?>"/><span class="btn-close" title="删除图片" onclick="$(this).parent().remove();"></span></div><?php endforeach; endif; else: echo "" ;endif; ?>
				     		</div>
				     		<script type="text/javascript">
							//上传图片
						    /* 初始化上传插件 */
							$("#upload_picture").uploadify({
						        "height"          : 30,
						        "swf"             : "/Public/static/uploadify/uploadify.swf",
						        "fileObjName"     : "download",
						        "buttonText"      : "上传图片",
						        "uploader"        : "<?php echo U('File/uploadPicture',array('session_id'=>session_id()));?>",
						        "width"           : 120,
						        'removeTimeout'	  : 1,
						        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
						        "onUploadSuccess" : uploadPicture,
						        'onFallback' : function() {
						            alert('未检测到兼容版本的Flash.');
						        }
						    });
							
							function uploadPicture(file, data){
						    	var data = $.parseJSON(data);
						    	var src = '';
						        if(data.status){
						        	src = data.url || '' + data.path;
						        	$("#upload_picture").parent().find('.upload-img-box').append(
						        		'<div class="upload-pre-item"><input type="hidden" name="pic[]" value="' + data.id + '"/><img src="' + src + '"/><span class="btn-close" title="删除图片" onclick="$(this).parent().remove();"></span></div>'
						        	);
						        } else {
						        	updateAlert(data.info);
						        	setTimeout(function(){
						                $('#top-alert').find('button').click();
						                $(that).removeClass('disabled').prop('disabled',false);
						            },1500);
						        }
						    }
							</script>
						</div>
					</div>
					<div class="form-item">
						<label class="item-label">兑换所需元宝</label>
						<div class="controls">
							<input type="text" class="text input-mini" name="price" value="<?php echo ($info["price"]); ?>" placeholder="元宝">
						</div>
					</div>
					<div class="form-item">
				     	<label class="item-label">商品库存</label>
				     	<div class="controls">
				     		<input type="text" class="text input-mini" name="quantity" value="<?php echo ($info["quantity"]); ?>" placeholder="件">
				     	</div>
				    </div>
					 <div class="form-item">
						 <label class="item-label">其他设置</label>
						 <div class="controls no-overview">
							 <label class="checkbox"><input name="is_home_show" value="1" type="checkbox" <?php if(($info["is_home_show"]) == "1"): ?>checked="true"<?php endif; ?> >首页显示</label>
						 </div>
					 </div>
				    <div class="form-item">
				     	<label class="item-label">商品状态</label>
				     	<div class="controls no-overview">
				     		<select name="status" title="状态" class="selectpicker" data-hide-disabled="true" data-size="5" data-live-search="true">
				    			<?php $_result=getStatus('product');if(is_array($_result)): $key = 0; $__LIST__ = $_result;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$val): $mod = ($key % 2 );++$key;?><option value="<?php echo ($key-1); ?>" <?php if(($info["status"]) == $key-1): ?>selected<?php endif; ?>><?php echo ($val); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
				    		</select>
				     	</div>
				    </div>
				    <div class="form-item">
				    	<label class="item-label">产品发货地址</label>
				    	<div class="controls no-overview">
				    		<select id="province" class="selectpicker" data-hide-disabled="true" data-size="5" data-live-search="true" name="province_id" title="省份">
				    			<?php $_result=getProvinces();if(is_array($_result)): $i = 0; $__LIST__ = $_result;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vo["province_id"]); ?>" <?php if(($info["province_id"]) == $vo["province_id"]): ?>selected<?php endif; ?>><?php echo ($vo["province"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
				    		</select>
				     		<script type="text/javascript">
				     		$(function(){
				     			$('#province').change(function(e){
				     				$('#city, #area').html('');
				     				$('#city, #area').selectpicker('refresh');
				     				
				     				paramter = {format : 'json', province_id : $(this).val()};
				     				
				     				$.post('<?php echo U('Api/Public/getCities');?>', paramter, function(data){
				     					if (data.code == 1) {
				     						$.each(data.data, function(i, item){
				     							$('#city').append('<option value="' + item.city_id + '">' + item.city + '</option>');
				     						});
				     						$('#city').selectpicker('refresh');
				     					}
				     				}, 'json');
				     			});
				     		});
				     		</script>
				     		<select id="city" class="selectpicker" data-hide-disabled="true" data-size="5" data-live-search="true" name="city_id" title="城市">
				     			<?php if(!empty($info["province_id"])): $_result=getCities($info['province_id']);if(is_array($_result)): $i = 0; $__LIST__ = $_result;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vo["city_id"]); ?>" <?php if(($info["city_id"]) == $vo["city_id"]): ?>selected<?php endif; ?>><?php echo ($vo["city"]); ?></option><?php endforeach; endif; else: echo "" ;endif; endif; ?>
				     		</select>
				     		<script type="text/javascript">
				     		$(function(){
				     			$('#city').change(function(e){
				     				$('#area').html('');
				     				$('#area').selectpicker('refresh');
				     				
				     				paramter = {format : 'json', city_id : $(this).val()};
				     				
				     				$.post('<?php echo U('Api/Public/getAreas');?>', paramter, function(data){
				     					if (data.code == 1) {
				     						$.each(data.data, function(i, item){
				     							$('#area').append('<option value="' + item.area_id + '">' + item.area + '</option>');
				     						});
				     						$('#area').selectpicker('refresh');
				     					}
				     				}, 'json');
				     			});
				     		});
				     		</script>
				     		<select id="area" class="selectpicker" data-hide-disabled="true" data-size="5" data-live-search="true" name="area_id" title="区县">
				     			<?php if(!empty($info["city_id"])): $_result=getAreas($info['city_id']);if(is_array($_result)): $i = 0; $__LIST__ = $_result;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vo["area_id"]); ?>" <?php if(($info["area_id"]) == $vo["area_id"]): ?>selected<?php endif; ?>><?php echo ($vo["area"]); ?></option><?php endforeach; endif; else: echo "" ;endif; endif; ?>
				     		</select>
				     	</div>
				     	<div class="controls">
				     		<input type="text" class="text input-large" name="address" value="<?php echo ($info["address"]); ?>" placeholder="详细地址">
				     	</div>
				     </div>
				 </div>
				 <div id="tab3" class="tab-pane tab3">
					<div class="form-item">
						<label class="item-label">所属店铺</label>
						<div class="controls">
							<input type="text" class="text input-4x" id="shop" onclick="$(this).val('');" value="<?php echo (get_table_field($info["shop_id"],'id','title','shop')); ?>" placeholder="店铺编号或名称">
							<input type="hidden" name="shop_id" value="<?php echo ($info["shop_id"]); ?>">
						</div>
						<script type="text/javascript">
							$(function($) {
					     		var action = '<?php echo U('Shop/autocomplete');?>';
					     		var input_val = $('input[name="shop_id"]');
					     		var shops = [];
					     		
					     		$('#shop').typeahead({
					     			source: function(query, process) {
					     				var parameter = {query: query, d: new Date()};
					     				
					     				$.post(action, parameter, function (data) {
					     					shops = data;
					     					
					     					var results = $.map(shops, function (shop) {
					                             return shop.id;
					                         });
					                         process(results);
					     				}, 'json');
					     			},
					     			
					     			matcher: function (item) {
					     				return true;
					     			},
					     			
					     			highlighter: function (item) {
					     				var shop = [];
					     				
					     				$.map(shops, function (u) {
					     					if (u.id == item) {
					     						shop = u;
					     					}
					     				});
					     				
					     				return shop.title + " (" + shop.id + ")";
					     			},
					
					     			updater: function (item) {
					     				input_val.val(item);
					     				
					     				var shop = [];
					     				
					     				$.map(shops, function (u) {
					     					if (u.id == item) {
					     						shop = u;
					     					}
					     				});
					     				
					     				return shop.title;
					     			}
					     	   });
					     	});
						</script>
					</div>
					<div class="form-item">
						<label class="item-label">商品分类</label>
						<div class="controls no-overview">
							<select class="selectpicker" data-hide-disabled="true" data-size="5" data-live-search="true" name="category_id" title="分类">
				     			<?php if(is_array($category_tree)): $i = 0; $__LIST__ = $category_tree;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$cate): $mod = ($i % 2 );++$i;?><option value="<?php echo ($cate["id"]); ?>" <?php if(($info["category_id"]) == $cate["id"]): ?>selected<?php endif; ?>><?php echo ($cate["title"]); ?></option>
			     					<?php if(is_array($cate["_child"])): $i = 0; $__LIST__ = $cate["_child"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$_child): $mod = ($i % 2 );++$i;?><option value="<?php echo ($_child["id"]); ?>" <?php if(($info["category_id"]) == $_child["id"]): ?>selected<?php endif; ?>>&nbsp;&nbsp;--&nbsp;&nbsp;<?php echo ($_child["title"]); ?></option><?php endforeach; endif; else: echo "" ;endif; endforeach; endif; else: echo "" ;endif; ?>
				     		</select>
				     	</div>
				     </div>
				 </div>
				 <div id="tab4" class="tab-pane tab4">
				 	<div class="form-item">
						<label class="item-label">服务保障</label>
						<div class="controls no-overview">
							<select class="selectpicker" name="security_7days" title="服务保障">
								<?php $_result=getStatus('security_7days');if(is_array($_result)): $key = 0; $__LIST__ = $_result;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$val): $mod = ($key % 2 );++$key;?><option value="<?php echo ($key-1); ?>" <?php if(($info["security_7days"]) == $key-1): ?>selected<?php endif; ?>><?php echo ($val); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
							</select>
						</div>
					</div>
					<div class="form-item">
						<label class="item-label">是否加入专题</label>
						<div class="controls no-overview">
							<dl class="checkmod">
								<dt class="hd">
									<label class="checkbox"><input type="checkbox" name="in_special_panic" <?php if(($info["in_special_panic"]) == "1"): ?>checked<?php endif; ?> value="1">加入抢购会</label>
								</dt>
								<dd class="bd">在 
									<select class="selectpicker" name="panic[special_panic_id]" data-live-search="true" data-size="5" title="时间段">
										<?php $_result=getSpecialPanic();if(is_array($_result)): $i = 0; $__LIST__ = $_result;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vo["id"]); ?>" 
						    				<?php if(($info["panic"]["special_panic_id"]) == $vo["id"]): ?>selected<?php endif; ?>>
						    				<?php echo (time_format($vo["start_time"],"H:i:s")); ?> - <?php echo (time_format($vo["end_time"],"H:i:s")); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
									</select> 时间段， 满 <input type="text" class="text input-mini" name="panic[condition_price]" value="<?php echo ($info["panic"]["condition_price"]); ?>" placeholder="元" />，打 
									<select class="selectpicker" name="panic[discount]" data-size="5" title="折扣">
										<?php $_result=getStatus('discount');if(is_array($_result)): $key = 0; $__LIST__ = $_result;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$val): $mod = ($key % 2 );++$key;?><option value="<?php echo ($key-1); ?>" <?php if(($info["panic"]["discount"]) == $key-1): ?>selected<?php endif; ?>><?php echo ($val); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
									</select>
								</dd>
							</dl>
						</div>
					</div>
					<!-- <div class="form-item">
						<label class="item-label">其他设置</label>
						<div class="controls no-overview">
							<label class="checkbox"><input name="is_home_show" value="1" type="checkbox" <?php if(($info["is_home_show"]) == "1"): ?>checked="true"<?php endif; ?> >首页显示</label>
						</div>
					</div> -->
				 </div>
				 <div id="tab5" class="tab-pane tab5">
				 	<div class="form-item">
						<label class="item-label"><a class="btn addOption">+ 选项</a><input type="text" class="text input-2x" placeholder="选项名称"></label>
						<div class="controls options">
							<?php if(is_array($info["options"])): $i = 0; $__LIST__ = $info["options"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><dl class="checkmod">
									<dt class="hd">
										<label class="checkbox"><?php echo ($vo["title"]); ?></label>
										<div class="fr">
											<a class="btn addOptionValue" data-id="<?php echo ($vo["id"]); ?>">+ 属性</a>
											<a class="btn delOption2" data-id="<?php echo ($vo["id"]); ?>">- 删除</a>
										</div>
									</dt>
									<dd class="bd">
										<div class="rule-check option-btn">
											<?php if(is_array($vo["_child"])): $i = 0; $__LIST__ = $vo["_child"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$child): $mod = ($i % 2 );++$i;?><div class="fl"><a class="btn" data-id="<?php echo ($child["id"]); ?>"><?php echo ($child["title"]); ?></a><span class="btn-close" data-id="<?php echo ($child["id"]); ?>" title="删除图片"></span></div><?php endforeach; endif; else: echo "" ;endif; ?>
										</div>
									</dd>
								</dl><?php endforeach; endif; else: echo "" ;endif; ?>
						</div>
					</div>
					<div class="form-item">
						<label class="item-label"><a class="btn addOptionPrice">+ 价钱</a><input type="text" class="text input-mini" placeholder="价格"></label>
						<div class="controls">
							<div class="data-table table-striped">
								<table class="">
									<thead>
										<tr>
											<th class="">选项</th>
											<th class="">价格</th>
											<th class="">操作</th>
										</tr>
									</thead>
									<tbody>
										<?php if(is_array($info["option_prices"])): $i = 0; $__LIST__ = $info["option_prices"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr class="OptionPriceTR">
												<td class=""><?php $_result=str2arr($vo['product_option_id']);if(is_array($_result)): $i = 0; $__LIST__ = $_result;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$child): $mod = ($i % 2 );++$i;?><a class="btn btn-mini"><?php echo (get_table_field($child,'id','title','product_option')); ?></a><?php endforeach; endif; else: echo "" ;endif; ?></td>
												<td class=""><input type="text" class="text input-mini" placeholder="价格" data-id="<?php echo ($vo["id"]); ?>" value="<?php echo ($vo["price"]); ?>"><span class="help-inline msg"></span></td>
												<td class=""><a class="btn delOptionPrice" data-id="<?php echo ($vo["id"]); ?>">删除</a></td>
											</tr><?php endforeach; endif; else: echo "" ;endif; ?>
									</tbody>
								</table>
							</div>
						</div>
					</div>
				 </div>
				 <div class="form-item">
			     	<button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
			     	<a class="btn btn-return" href="<?php echo U('Product/index');?>">返 回</a>
			     	<input type="hidden" name="type" value="<?php echo ($info["type"]); ?>">
			     	<input type="hidden" name="id" value="<?php echo ($info["id"]); ?>">
			     </div>
			</form>
		</div>
	</div>

        </div>
        <div class="cont-ft">
            <div class="copyright">
                <div class="fl">感谢使用 惠Go 管理平台</div>
                <div class="fr">V<?php echo (ONETHINK_VERSION); ?></div>
            </div>
        </div>
    </div>
    <?php if(!empty($expireAdCount)): ?><div class="dialog-right-bottom">
	    	<a href="javascript:;" class="close">&times;</a>
	    	<div class="dialog-content">
	    		<a href="<?php echo U('Ad/index');?>">有<?php echo ($expireAdCount); ?>个广告位马上到期，点击查看>></a>
	    	</div>
	    	<script type="text/javascript">
	    	$(function(){
	    		$(".dialog-right-bottom > .close").click(function(){
	    			$(".dialog-right-bottom").fadeOut();
	    		});
	    	});
	    	</script>
	    </div><?php endif; ?>
    <!-- /内容区 -->
    <script type="text/javascript">
    (function(){
        var ThinkPHP = window.Think = {
            "ROOT"   : "", //当前网站地址
            "APP"    : "", //当前项目地址
            "PUBLIC" : "/Public", //项目公共目录地址
            "DEEP"   : "<?php echo C('URL_PATHINFO_DEPR');?>", //PATHINFO分割符
            "MODEL"  : ["<?php echo C('URL_MODEL');?>", "<?php echo C('URL_CASE_INSENSITIVE');?>", "<?php echo C('URL_HTML_SUFFIX');?>"],
            "VAR"    : ["<?php echo C('VAR_MODULE');?>", "<?php echo C('VAR_CONTROLLER');?>", "<?php echo C('VAR_ACTION');?>"]
        }
    })();
    </script>
    <script type="text/javascript" src="/Public/static/think.js"></script>
    <script type="text/javascript" src="/Public/Admin/js/common.js"></script>
    <script type="text/javascript">
        +function(){
            var $window = $(window), $subnav = $("#subnav"), url;
            $window.resize(function(){
                $("#main").css("min-height", $window.height() - 130);
            }).resize();

            /* 左边菜单高亮 */
            url = window.location.pathname + window.location.search;
            url = url.replace(/(\/(p)\/\d+)|(&p=\d+)|(\/(id)\/\d+)|(&id=\d+)|(\/(group)\/\d+)|(&group=\d+)/, "");
            $subnav.find("a[href='" + url + "']").parent().addClass("current");

            /* 左边菜单显示收起 */
            $("#subnav").on("click", "h3", function(){
                var $this = $(this);
                $this.find(".icon").toggleClass("icon-fold");
                $this.next().slideToggle("fast").siblings(".side-sub-menu:visible").
                      prev("h3").find("i").addClass("icon-fold").end().end().hide();
            });

            $("#subnav h3 a").click(function(e){e.stopPropagation()});

            /* 头部管理员菜单 */
            $(".user-bar").mouseenter(function(){
                var userMenu = $(this).children(".user-menu ");
                userMenu.removeClass("hidden");
                clearTimeout(userMenu.data("timeout"));
            }).mouseleave(function(){
                var userMenu = $(this).children(".user-menu");
                userMenu.data("timeout") && clearTimeout(userMenu.data("timeout"));
                userMenu.data("timeout", setTimeout(function(){userMenu.addClass("hidden")}, 100));
            });

	        /* 表单获取焦点变色 */
	        $("form").on("focus", "input", function(){
		        $(this).addClass('focus');
	        }).on("blur","input",function(){
				        $(this).removeClass('focus');
			        });
		    $("form").on("focus", "textarea", function(){
			    $(this).closest('label').addClass('focus');
		    }).on("blur","textarea",function(){
			    $(this).closest('label').removeClass('focus');
		    });

            // 导航栏超出窗口高度后的模拟滚动条
            var sHeight = $(".sidebar").height();
            var subHeight  = $(".subnav").height();
            var diff = subHeight - sHeight; //250
            var sub = $(".subnav");
            if(diff > 0){
                $(window).mousewheel(function(event, delta){
                    if(delta>0){
                        if(parseInt(sub.css('marginTop'))>-10){
                            sub.css('marginTop','0px');
                        }else{
                            sub.css('marginTop','+='+10);
                        }
                    }else{
                        if(parseInt(sub.css('marginTop'))<'-'+(diff-10)){
                            sub.css('marginTop','-'+(diff-10));
                        }else{
                            sub.css('marginTop','-='+10);
                        }
                    }
                });
            }
        }();
    </script>
    
<link rel="stylesheet" type="text/css" href="/Public/static/bootstrap/css/bootstrap-select.css" />
<link rel="stylesheet" type="text/css" href="/Public/static/bootstrap/css/bootstrap-typeahead.css" />
<link rel="stylesheet" type="text/css" href="/Public/static/videojs/css/video-js-5.2.1.css" />
<script type="text/javascript" src="/Public/static/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="/Public/static/bootstrap/js/bootstrap-select.js"></script>
<script type="text/javascript" src="/Public/static/bootstrap/js/bootstrap-typeahead.js"></script>
<script type="text/javascript" src="/Public/static/videojs/js/video-js-5.2.1.js"></script>
<script type="text/javascript">
//导航高亮
highlight_subnav('<?php echo U('Product/index');?>');

$(function(){
	$(".tab-nav li").click(function(){
        var self = $(this), target = self.data("tab");
        self.addClass("current").siblings(".current").removeClass("current");
        window.location.hash = "#" + target.substr(3);
        $(".tab-pane.in").removeClass("in");
        $("." + target).addClass("in");
        //preloadvideo();
    }).filter("[data-tab=tab" + window.location.hash.substr(1) + "]").click();

	var time = 200;
	var timeout = null;
	
	$(document).delegate(".addOption", "click", function(){
		input = $(this).next('input');
		val = input.val().trim();
		if (val == "") {
			updateAlert('请填写选项名称');
			input.focus();
            setTimeout(function(){
            	$('#top-alert').find('button').click();
            },1500);
		} else {
			product_id = "<?php echo ($info["id"]); ?>";
			paramter = {product_id: product_id, text: val};
			
			$.post('<?php echo U('Product/editOption');?>', paramter, function(data){
				if (data.status == 1) {
					input.val('');
					data_id = data.data.id;
					$('.options').append('<dl class="checkmod"><dt class="hd"><label class="checkbox">' + val + '</label><div class="fr"><a class="btn addOptionValue" data-id="' + data_id + '">+ 属性</a><a class="btn delOption" data-id="' + data_id + '">- 删除</a></div></dt><dd class="bd"><div class="rule-check option-btn"></div></dd></dl>');
				} else {
					updateAlert(data.message);
                    setTimeout(function(){
                    	$('#top-alert').find('button').click();
                    },1500);
				}
			}, 'json');
		}
	});
	
	$(document).delegate(".delOption", "click", function(){
		if(confirm("确认要删除该选项？")) {
			self = $(this);
			id = self.attr('data-id');
			paramter = {id: id};
			
			$.post('<?php echo U('Product/deleteOption');?>', paramter, function(data){
				if (data.status == 1) {
					self.closest('.checkmod').remove();
				} else {
					updateAlert(data.message);
                    setTimeout(function(){
                    	$('#top-alert').find('button').click();
                    },1500);
				}
			}, 'json');
		}
	});

    $(document).delegate(".delOption2", "click", function(){
        if(confirm("确认要删除该选项？")) {
            self = $(this);
            id = self.attr('data-id');
            paramter = {id: id};

            $.post('<?php echo U('Product/deleteOption2');?>', paramter, function(data){
                if (data.status == 1) {
                    self.closest('.checkmod').remove();
                } else {
                    updateAlert(data.message);
                    setTimeout(function(){
                        $('#top-alert').find('button').click();
                    },1500);
                }
            }, 'json');
        }
    });
	
	$(document).delegate(".addOptionValue", "click", function(){
		pid = $(this).attr('data-id');
		$(this).closest('.checkmod').find('.option-btn').append('<div class="fl"><a data-pid="' + pid + '"><input type="text" class="text input-mini"></a></div>');
		$(this).closest('.checkmod').find('.option-btn input').focus();
	});
	
	$(document).delegate(".option-btn .btn", "click", function(){
		var self = $(this);
        clearTimeout(timeout);
        
        timeout = setTimeout(function(){
        	self.closest('.option-btn').find('.btn').removeClass('selected');
        	self.addClass('selected');
        }, time);
	});
	
	$(document).delegate(".option-btn .btn", "dblclick", function(){
		clearTimeout(timeout);
		
		var self = $(this), text = $(this).text(), pid = $(this).attr("data-pid") == undefined ? 0 : $(this).attr("data-pid"), id = $(this).attr("data-id") == undefined ? 0 : $(this).attr("data-id");
		self.removeClass('btn');
		self.html('<input type="text" class="text input-mini" placeholder="' + text + '">');
		self.find('input').focus();
	});
	
	$(document).delegate(".option-btn input", "blur", function(){
		var self = $(this);
		id = self.parent().attr('data-id') == undefined ? 0 : self.parent().attr('data-id');
		pid = self.parent().attr('data-pid') == undefined ? 0 : self.parent().attr('data-pid');
		text = self.val().trim();
		text =  text == "" ? self.attr('placeholder') : text;
		
		if (text == "" || text == undefined) {
			self.parent().remove();
			return false;
		}
		
		paramter = {id: id, pid: pid, text: text};
		
		$.post('<?php echo U('Product/editOption');?>', paramter, function(data){
			if (data.status == 1) {
				text += '<span class="btn-close" data-id="' + data.data.id + '" title="删除图片"></span>';
				self.parent().addClass('btn');
				self.parent().attr('data-id', data.data.id);
				self.parent().html(text);
			} else {
				self.parent().remove();
				updateAlert(data.message);
                setTimeout(function(){
                	$('#top-alert').find('button').click();
                },1500);
			}
		}, 'json');
	});
	
	$(document).delegate(".option-btn input", "keyup", function(e){
        if(e.keyCode==13){
        	$(this).blur();
        }
    });
	
	$(document).delegate(".option-btn .btn-close", "click", function(){
		if(confirm("确认要删除该属性？")) {
			self = $(this);
			id = self.attr('data-id');
			paramter = {id: id};
			
			$.post('<?php echo U('Product/deleteOption');?>', paramter, function(data){
				if (data.status == 1) {
					self.parent().remove();
				} else {
					updateAlert(data.message);
                    setTimeout(function(){
                    	$('#top-alert').find('button').click();
                    },1500);
				}
			}, 'json');
		}
	});
	
	$('.addOptionPrice').click(function(){
		var ids = new Array(), texts = new Array(), self = $(this), input = $(this).next('input');
		
		$.each($('.option-btn .selected'), function(i, item){
			id = $(item).attr('data-id');
			text = $(item).text();
			ids.push(id);
			texts.push(text);
		});
		
		product_id = "<?php echo ($info["id"]); ?>";
		price = input.val().trim();
		paramter = {product_id: product_id, ids: ids, price: price};
		
		$.post('<?php echo U('Product/addOptionPrice');?>', paramter, function(data){
			if (data.status == 1) {
				input.val('');
				items = '';
				$.each(texts, function(i, item){
					items += '<a class="btn btn-mini">' + item + '</a>';
				});
				
				self.closest('.form-item').find('tbody').append('<tr class="OptionPriceTR"><td class="">' + items + '</td><td class=""><input type="text" class="text input-mini" placeholder="价格" data-id="' + data.data.id + '" value="' + price +'"><span class="help-inline msg"></span></td><td class=""><a class="btn delOptionPrice" data-id="' + data.data.id + '">删除</a></td></tr>');
			} else {
				updateAlert(data.message);
				setTimeout(function(){
					$('#top-alert').find('button').click();
				},1500);
			}
		}, 'json');
	});
	
	$(document).delegate(".delOptionPrice", "click", function(){
		if(confirm("确认要删除该属性？")) {
			self = $(this);
			id = self.attr('data-id');
			paramter = {id: id};
			
			$.post('<?php echo U('Product/deleteOptionPrice');?>', paramter, function(data){
				if (data.status == 1) {
					self.closest('tr').remove();
				} else {
					updateAlert(data.message);
					setTimeout(function(){
						$('#top-alert').find('button').click();
					},1500);
				}
			}, 'json');
			
		}
	});
	
	$(document).delegate(".OptionPriceTR input", "click", function(){
		var self = $(this);
		self.data('param', self.val());
	});
	
	$(document).delegate(".OptionPriceTR input", "blur", function(){
		var self = $(this);
		if (self.data('param') != self.val()) {
			id = self.attr('data-id');
			price = self.val();
			paramter = {id: id, price: price};
			
			$.post('<?php echo U('Product/editOptionPrice');?>', paramter, function(data){
				var name = data.status ? "success" : "error", msg;
				msg = self.next(".msg").addClass(name).text(data.message).css("display", "inline-block");
				setTimeout(function(){
					msg.fadeOut(function(){
						msg.text("").removeClass(name);
					});
				}, 1000);
			}, 'json');
		}
	});
	
	$(document).delegate(".OptionPriceTR input", "keyup", function(e){
        if(e.keyCode==13){
        	$(this).blur();
        }
    });
});

document.onkeydown = function(event) {  
    var target, code, tag;  
    if (!event) {  
        event = window.event; //针对ie浏览器  
        target = event.srcElement;  
        code = event.keyCode;  
        if (code == 13) {  
            tag = target.tagName;  
            if (tag == "TEXTAREA") { return true; }  
            else { return false; }  
        }  
    }  
    else {  
        target = event.target; //针对遵循w3c标准的浏览器，如Firefox  
        code = event.keyCode;  
        if (code == 13) {  
            tag = target.tagName;  
            if (tag == "INPUT") { return false; }  
            else { return true; }   
        }  
    }  
};
</script>

</body>
</html>